//
//  XMAccountDetailViewController.m
//  MyNewProject
//
//  Created by ZhangYuan on 2019/1/30.
//  Copyright © 2019年 sun. All rights reserved.
//

#import "XMAccountDetailViewController.h"

@interface XMAccountDetailViewController ()
@property(nonatomic , retain)UIView * backView;
@property(nonatomic , retain)UIView * redLineView;
@end

@implementation XMAccountDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gk_navigationBar.hidden = NO;
    self.gk_navTitle = @"明细";
    itemWidth = (SCREEN_WIDTH - 40)/3.0;
    [self.view addSubview:self.backView];
}
-(void)titleButtonPress:(UIButton *)button{
    NSInteger i = button.tag - 1000;
    for (NSInteger x = 0; x<3; x++) {
        UIButton * btn = (UIButton *)[self.backView viewWithTag:1000 + x];
        if (x == i) {
             [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        }else{
            [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }
    }
    [UIView animateWithDuration:0.3 animations:^{
        self.redLineView.frame = CGRectMake(((SCREEN_WIDTH - 40)/3.0) * i, 0, (SCREEN_WIDTH - 40)/3.0, 40);
    } completion:^(BOOL finished) {
       
    }];
}
-(UIView *)backView{
    if (!_backView) {
        _backView = [[UIView alloc]initWithFrame:CGRectMake(20, (IS_IPhoneX_All?88:64) + 10, SCREEN_WIDTH - 40, 40)];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.cornerRadius = 20;
        _backView.clipsToBounds = YES;
        _backView.layer.borderColor = [UIColor redColor].CGColor;
        _backView.layer.borderWidth = 1.0f;
        
        [_backView addSubview:self.redLineView];
        
        NSArray * titleArr = @[@"提现",@"充值",@"奖励"];
        for (NSInteger i = 0; i<[titleArr count]; i++) {
            UIButton * titleButton = [UIButton buttonWithType:UIButtonTypeCustom];
            titleButton.frame = CGRectMake(itemWidth * i, 0, itemWidth, 40);
            titleButton.tag = 1000 + i;
            titleButton.backgroundColor = [UIColor clearColor];
            [titleButton setTitleColor:i == 0?[UIColor whiteColor]:[UIColor redColor] forState:UIControlStateNormal];
            [titleButton setTitle:titleArr[i] forState:UIControlStateNormal];
            titleButton.titleLabel.font = LightFont(14);
            [titleButton addTarget:self action:@selector(titleButtonPress:) forControlEvents:UIControlEventTouchUpInside];
            [_backView addSubview:titleButton];
        }
    }
    return _backView;
}
-(UIView *)redLineView{
    if (!_redLineView) {
        _redLineView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, itemWidth, 40)];
        _redLineView.backgroundColor = [UIColor redColor];
        _redLineView.layer.cornerRadius = 20;
        _redLineView.clipsToBounds = YES;
    }
    return _redLineView;
}
@end
